import querystring from "querystring"
export default (req,res,next)=>{
    //1.过滤get请求
    if(req.method.toLowerCase() === "get"){
        return next();
    }
    //2.处理post 请求
    //如果头部是application/x-www-form-urlencoded 则需要处理
    //如果头部是multipart/form-data 则不需要处理
    if(req.headers["content-type"].startsWith("multipart/form-data")){
        return next()
    }
    
    var data = ''
    req.on("data",(chunck)=>{
        data += chunck;
    })
    req.on("end",()=>{
        req.body = querystring.parse(data);
        next()
    })
}